var express = require('express');
var router = express.Router();
var {WikipediaModel,petDetailsModel} = require('../db/wikipediaModel')

/* GET home page. */
router.get('/', function(req, res, next) {
  res.render('index', { title: 'Express' });
});

router.get('/pets',async function(req,res){
    let data = await WikipediaModel.find()
    res.send({
        code:200,
        msg:"成功",
        data
    })
})

router.get('/petDetails',async function(req,res){
    let {id} = req.query
    let data = await petDetailsModel.findOne({_id:id})
    res.send({
        code:200,
        msg:'成功',
        data
    })
})

router.post('/addLooks',async function(req,res){
    let {_id} = req.body
    let looknum = await WikipediaModel.findOne({_id})
    await WikipediaModel.findByIdAndUpdate({_id},{$set:{look:looknum.look+1}})

    res.send({

    })
})


module.exports = router;